#include "keythread.h"

KeyThread::KeyThread(int key, int interval)
{
    this->key = key;
    this->interval = interval;
}

KeyThread::~KeyThread()
{
}

void KeyThread::setState(int state)
{
    this->state = state;
}

void KeyThread::run()
{
    INPUT input[2];
    memset(input, 0, sizeof(input));
    while(true)
    {
        if (state == 1)
        {
            input[0].type = input[1].type = INPUT_KEYBOARD;
            input[0].ki.wVk = input[1].ki.wVk = key;

            input[1].ki.dwFlags = KEYEVENTF_KEYUP;
            SendInput(1, &input[0], sizeof(INPUT));
            SendInput(1, &input[1], sizeof(INPUT));
            QThread::msleep(this->interval);
        }
        else if (state == 2)
        {
            continue;
        }

    }
}
